const mysql = require('mysql')
const config = require('../config')

class Db
{
  static query(data){
    return new Promise((resolve, reject) => {
      let pool = mysql.createPool(config.db)
      pool.getConnection((err, connection)=>{
        if(err){
          // console.log("建立连接失败");
          resolve(['数据库连接失败','',''])
          pool.end()
        } else {
          // console.log("建立连接成功");
          let params = {sql:'',values:[],...data}
          connection.query(params,function(err,results,fields){
            resolve([err,results,fields])
            pool.end()
          })
        }
      })
    });
  }
}

module.exports = Db